package com.ruoyi.web.controller.estate;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.estate.Pet;
import com.ruoyi.system.service.estate.IPetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宠物管理Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/estate/pet")
public class PetController extends BaseController
{
    @Autowired
    private IPetService petService;

    /**
     * 查询宠物列表
     */
    @PreAuthorize("@ss.hasPermi('estate:pet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pet pet)
    {
        startPage();
        List<Pet> list = petService.selectPetList(pet);
        return getDataTable(list);
    }

    /**
     * 导出宠物列表
     */
    @PreAuthorize("@ss.hasPermi('estate:pet:export')")
    @Log(title = "宠物管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Pet pet)
    {
        List<Pet> list = petService.selectPetList(pet);
        ExcelUtil<Pet> util = new ExcelUtil<Pet>(Pet.class);
        return util.exportExcel(list, "宠物数据");
    }

    /**
     * 获取宠物详细信息
     */
    @PreAuthorize("@ss.hasPermi('estate:pet:query')")
    @GetMapping(value = "/{petId}")
    public AjaxResult getInfo(@PathVariable("petId") Long petId)
    {
        return AjaxResult.success(petService.selectPetById(petId));
    }

    /**
     * 新增宠物
     */
    @PreAuthorize("@ss.hasPermi('estate:pet:add')")
    @Log(title = "宠物管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Pet pet)
    {
        return toAjax(petService.insertPet(pet));
    }

    /**
     * 修改宠物
     */
    @PreAuthorize("@ss.hasPermi('estate:pet:edit')")
    @Log(title = "宠物管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Pet pet)
    {
        return toAjax(petService.updatePet(pet));
    }

    /**
     * 删除宠物
     */
    @PreAuthorize("@ss.hasPermi('estate:pet:remove')")
    @Log(title = "宠物管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{petIds}")
    public AjaxResult remove(@PathVariable Long[] petIds)
    {
        return toAjax(petService.deletePetByIds(petIds));
    }
} 